package org.ytor.core.sqlflow.dsl.template;

import org.ytor.core.sqlflow.dsl.template.node.TemplateNode;
import org.ytor.core.sqlflow.dsl.template.node.support.BlockNode;
import org.ytor.core.sqlflow.dsl.template.node.support.ForNode;
import org.ytor.core.sqlflow.dsl.template.node.support.IfNode;
import org.ytor.core.sqlflow.dsl.template.node.support.TextNode;

/**
 * 模板AST树打印
 */
public class TemplateAstPrinter {

    public static void print(TemplateNode node, int indent) {
        String pad = "  ".repeat(indent);
        if (node instanceof TextNode t) {
            System.out.println(pad + "Text: " + t.text);
        } else if (node instanceof BlockNode b) {
            System.out.println(pad + "Block:");
            for (TemplateNode child : b.children) {
                print(child, indent + 1);
            }
        } else if (node instanceof IfNode i) {
            System.out.println(pad + "If: " + i.condition);
            print(i.body, indent + 1);
        } else if (node instanceof ForNode f) {
            System.out.println(pad + "For: " + f.listVar);
            print(f.body, indent + 1);
        }
    }

}
